import axios from 'axios'

const service = axios.create({
  // 设置超时时间
  timeout: 20000,
  baseURL: process.env.BASE_URL,
  headers: {
    'Content-Type': 'application/json;charset=UTF-8'
  }
})
/**
 * 请求前拦截
 * 用于处理需要在请求前的操作
 */
service.interceptors.request.use(config => {
  const token = localStorage.getItem('TOKEN')
  const brandmsg = JSON.parse(localStorage.getItem('BRANDMSG')) || null
  // console.log(token, account)
  if (token && brandmsg) {
    // 设置请求头
    config.headers['token'] = token
    config.headers['brandId'] = brandmsg.brandId
  }
  // console.log('请求拦截', config)
  return config
}, (error) => {
  return Promise.reject(error)
})

export default service
